libxc: osdep: convert do_xen_hypercall()
authorIan Campbell <ian.campbell@citrix.com>
Fri, 3 Dec 2010 09:36:46 +0000 (09:36 +0000)
committerIan Campbell <ian.campbell@citrix.com>
Fri, 3 Dec 2010 09:36:46 +0000 (09:36 +0000)
do_privcmd() was only ever used by do_xen_hypercall() so remove it.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Ian Jackson <ian.jackson.citrix.com>
tools/libxc/xc_linux.c
tools/libxc/xc_minios.c
tools/libxc/xc_netbsd.c
tools/libxc/xc_private.c
tools/libxc/xc_solaris.c
tools/libxc/xenctrlosdep.h

index 5c9e70c06570ddbe7b2d92b43d7cca028d5f59a9..a0539cd0b5e48eabab933dd9e6168de540dea326 100644 (file)
@@ -75,6 +75,12 @@ static int linux_privcmd_close(xc_interface *xch, xc_osdep_handle h)
     return close(fd);
 }
 
+static int linux_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcmd_hypercall_t *hypercall)
+{
+    int fd = (int)h;
+    return ioctl(fd, IOCTL_PRIVCMD_HYPERCALL, hypercall);
+}
+
 static int xc_map_foreign_batch_single(xc_interface *xch, uint32_t dom,
                                        xen_pfn_t *mfn, unsigned long addr)
 {
@@ -316,20 +322,13 @@ void *xc_map_foreign_ranges(xc_interface *xch, uint32_t dom, size_t size, int pr
     return ret;
 }
 
-static int do_privcmd(xc_interface *xch, int cmd, unsigned long data)
-{
-    return ioctl(xch->fd, cmd, data);
-}
-
-int do_xen_hypercall(xc_interface *xch, privcmd_hypercall_t *hypercall)
-{
-    return do_privcmd(xch, IOCTL_PRIVCMD_HYPERCALL,
-                      (unsigned long)hypercall);
-}
-
 static struct xc_osdep_ops linux_privcmd_ops = {
     .open = &linux_privcmd_open,
     .close = &linux_privcmd_close,
+
+    .u.privcmd = {
+        .hypercall = &linux_privcmd_hypercall,
+    },
 };
 
 #define DEVXEN "/dev/xen/"
index d822cf3e4796f480754d0d5288c1a939b334a12f..076605a743a37755f3eedf1e737b82d40a5fdef9 100644 (file)
@@ -71,6 +71,28 @@ void minios_interface_close_fd(int fd)
     files[fd].type = FTYPE_NONE;
 }
 
+static int minios_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcmd_hypercall_t *hypercall)
+{
+    multicall_entry_t call;
+    int i, ret;
+
+    call.op = hypercall->op;
+    for (i = 0; i < sizeof(hypercall->arg) / sizeof(*hypercall->arg); i++)
+       call.args[i] = hypercall->arg[i];
+
+    ret = HYPERVISOR_multicall(&call, 1);
+
+    if (ret < 0) {
+       errno = -ret;
+       return -1;
+    }
+    if ((long) call.result < 0) {
+        errno = - (long) call.result;
+        return -1;
+    }
+    return call.result;
+}
+
 void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot,
                           const xen_pfn_t *arr, int *err, unsigned int num)
 {
@@ -157,31 +179,13 @@ void *xc_map_foreign_ranges(xc_interface *xch, uint32_t dom,
 }
 
 
-int do_xen_hypercall(xc_interface *xch, privcmd_hypercall_t *hypercall)
-{
-    multicall_entry_t call;
-    int i, ret;
-
-    call.op = hypercall->op;
-    for (i = 0; i < sizeof(hypercall->arg) / sizeof(*hypercall->arg); i++)
-       call.args[i] = hypercall->arg[i];
-
-    ret = HYPERVISOR_multicall(&call, 1);
-
-    if (ret < 0) {
-       errno = -ret;
-       return -1;
-    }
-    if ((long) call.result < 0) {
-        errno = - (long) call.result;
-        return -1;
-    }
-    return call.result;
-}
-
 static struct xc_osdep_ops minios_privcmd_ops = {
     .open = &minios_privcmd_open,
     .close = &minios_privcmd_close,
+
+    .u.privcmd = {
+        .hypercall = &minios_privcmd_hypercall,
+    },
 };
 
 static xc_osdep_handle minios_evtchn_open(xc_evtchn *xce)
index 397c4fb71f7e27097f736594406fef4be236da35..3c3b90d178fcccfa67eca768aee7ea3af6a5a549 100644 (file)
@@ -68,6 +68,17 @@ static int netbsd_privcmd_close(xc_interface *xch, xc_osdep_handle h)
     return close(fd);
 }
 
+static int netbsd_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcmd_hypercall_t *hypercall)
+{
+    int fd = (int)h;
+    int error = ioctl(fd, IOCTL_PRIVCMD_HYPERCALL, hypercall);
+
+    if (error < 0)
+        return -errno;
+    else
+        return hypercall->retval;
+}
+
 void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
                            xen_pfn_t *arr, int num)
 {
@@ -161,30 +172,13 @@ mmap_failed:
        return NULL;
 }
 
-
-static int do_privcmd(xc_interface *xch, unsigned int cmd, unsigned long data)
-{
-    int err = ioctl(xch->fd, cmd, data);
-    if (err == 0)
-       return 0;
-    else
-       return -errno;
-}
-
-int do_xen_hypercall(xc_interface *xch, privcmd_hypercall_t *hypercall)
-{
-    int error = do_privcmd(xch,
-                      IOCTL_PRIVCMD_HYPERCALL,
-                      (unsigned long)hypercall);
-    if (error)
-       return error;
-    else
-       return (hypercall->retval);
-}
-
 static struct xc_osdep_ops netbsd_privcmd_ops = {
     .open = &netbsd_privcmd_open,
     .close = &netbsd_privcmd_close,
+
+    .u.privcmd = {
+        .hypercall = &netbsd_privcmd_hypercall;
+    },
 };
 
 #define EVTCHN_DEV_NAME  "/dev/xenevt"
index 3a0ce3509831d8526adfa96f84607e74cdbdd8f3..aaa0d34ce3dcb5a4d4558913a0d5007238c81966 100644 (file)
@@ -139,6 +139,12 @@ int xc_interface_close(xc_interface *xch)
     return xc_interface_close_common(xch);
 }
 
+
+int do_xen_hypercall(xc_interface *xch, privcmd_hypercall_t *hypercall)
+{
+    return xch->ops->u.privcmd.hypercall(xch, xch->ops_handle, hypercall);
+}
+
 xc_evtchn *xc_evtchn_open(xentoollog_logger *logger,
                              unsigned open_flags)
 {
index 062b74249eb22a012238be434be124f32851e043..cdcc2222c42832f19de9c6508c85d2263f68aeed 100644 (file)
@@ -68,6 +68,12 @@ static int solaris_privcmd_close(xc_interface *xch, xc_osdep_handle h)
     return close(fd);
 }
 
+static int solaris_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcmd_hypercall_t *hypercall)
+{
+    int fd = (int)h;
+    return ioctl(fd, IOCTL_PRIVCMD_HYPERCALL, hypercall);
+}
+
 void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
                            xen_pfn_t *arr, int num)
 {
@@ -156,21 +162,13 @@ mmap_failed:
     return NULL;
 }
 
-static int do_privcmd(xc_interface *xch, unsigned int cmd, unsigned long data)
-{
-    return ioctl(xch->fd, cmd, data);
-}
-
-int do_xen_hypercall(xc_interface *xch, privcmd_hypercall_t *hypercall)
-{
-    return do_privcmd(xch,
-                      IOCTL_PRIVCMD_HYPERCALL,
-                      (unsigned long)hypercall);
-}
-
 static struct xc_osdep_ops solaris_privcmd_ops = {
     .open = &solaris_privcmd_open,
     .close = &solaris_privcmd_close,
+
+    .u.privcmd = {
+        .hypercall = &solaris_privcmd_hypercall;
+    },
 };
 
 static xc_osdep_handle solaris_evtchn_open(xc_evtchn *xce)
index f807d0d2dca4764aa83c8a507ddde6bd4c7a432a..59928fb7b7ac7862580a2981fd656b53a09e5dc9 100644 (file)
@@ -59,6 +59,12 @@ struct xc_osdep_ops
     xc_osdep_handle (*open)(xc_interface *xch);
 
     int (*close)(xc_interface *xch, xc_osdep_handle h);
+
+    union {
+        struct {
+            int (*hypercall)(xc_interface *xch, xc_osdep_handle h, privcmd_hypercall_t *hypercall);
+        } privcmd;
+    } u;
 };
 typedef struct xc_osdep_ops xc_osdep_ops;